<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>replace() 方法使用正则表达式</title>
</head>

<!-- 使用正则表达式且不区分大小写将字符串中的 Microsoft 替换为 Runoob  -->

<body>
    <p>替换 "microsoft" 为 "Runoob" :</p>
    <button onclick="myFunction()">点我</button>
    <p id="demo">Visit Microsoft!</p>
    <script>
        function myFunction() {
            var str = document.getElementById("demo").innerHTML;
            var txt = str.replace(/microsoft/i, "Runoob");
            document.getElementById("demo").innerHTML = txt;
        }
    </script>
</body>

</html>